package com.kingdee.hackson.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IDConvertUtils {

    private static Logger logger = LoggerFactory.getLogger(IDConvertUtils.class);

    private static Long MIN_ID = 1269600871000000000L;

    private static Long MAX_ID = 1269600872000000000L;

    private static Long SHORT_MIN_ID = 0L;

    private static Long SHORT_MAX_ID = 10000000L;

    private static Long TIMES = getTims();

    public static Long encodeToLongId(long shortId) {
        return MIN_ID + TIMES * shortId;
    }

    public static Long decodeToShortId(Long longId) {
        return (longId - MIN_ID) / TIMES;
    }

    private static Long getTims() {
        // long times = (MAX_ID - MIN_ID) / (SHORT_MAX_ID - SHORT_MIN_ID);
        return 103L;
    }

    public static void main(String[] args) {
        long data = 1234567L;
        Long aLong = encodeToLongId(data);
        Long aLong1 = decodeToShortId(aLong);
        logger.info("source data={}, encode data={},decode data = {}", data, aLong, aLong1);
    }
}
